
<link rel="shortcut  icon" type="image/x-icon" href="img/icon/favicon.ico" media="screen">
<!-- 框架样式 -->
<link type="text/css" rel="stylesheet" href="${static}/fonts/font-icons.min.css">
<link type="text/css" rel="stylesheet" href="${static}/css/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="${static}/plugin/layui/css/layui.css">
<link type="text/css" rel="stylesheet" href="${static}/plugin/datatable/media/css/dataTables.bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="${static}/plugin/bootstrap-select/css/bootstrap-select.min.css?r=0.020456797551074324">
<link rel="stylesheet" type="text/css" href="${static}/plugin/bootstrap-datetimepicker-master/css/bootstrap-datetimepicker.css">
<link type="text/css" rel="stylesheet" href="${static}/plugin/radioCheckBox/src/pretty.min.css">
<link type="text/css" rel="stylesheet" href="${static}/plugin/materialdesignicons/css/materialdesignicons.min.css">
<link async rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/material-design-iconic-font/2.2.0/css/material-design-iconic-font.min.css"/>
<link type="text/css" rel="stylesheet" href="${static}/plugin/radioCheckBox/src/pretty.min.css">
<link type="text/css" rel="stylesheet" href="${static}/plugin/drag/drag.css">
<link type="text/css" rel="stylesheet" href="${static}/plugin/calendar/simple-calendar.css">
<link type="text/css" rel="stylesheet" href="${static}/plugin/weather/leoweather.css">
<link rel="stylesheet" type="text/css" href="${static}/plugin/imgupload/css/cropper.min.css?r=0.6207188189209538">
<link rel="stylesheet" type="text/css" href="${static}/plugin/imgupload/css/mui.min.css?r=0.9207463414125734">
<link type="text/css" rel="stylesheet" href="${static}/plugin/jquery-plugin-circliful-master/css/jquery.circliful.css">

<!-- 自定义样式 -->
<link type="text/css" rel="stylesheet" href="${static}/css/fream.css"> <!-- 顶部和侧边 -->
<link type="text/css" rel="stylesheet" href="${static}/css/iconfont.css">
<link type="text/css" rel="stylesheet" href="${static}/css/main.css?r=0.4389791385058335">
<link type="text/css" rel="stylesheet" href="${static}/css/nav.css">
<link rel="stylesheet" type="text/css" href="${static}/css/processHelper.css?r=0.07160859914374484">
<link type="text/css" rel="stylesheet" href="${static}/css/dtable.css">
<link type="text/css" rel="stylesheet" href="${static}/page/back/firstpage/css/firstpage.css"><!-- 主页css -->
<link type="text/css" rel="stylesheet" href="${static}/css/btn.css">
<link type="text/css" rel="stylesheet" href="${static}/page/back/device/css/icon.css">

<link type="text/css" rel="stylesheet" href="${static}/page/back/customprint/file/cpTemple.css">
<link type="text/css" rel="stylesheet" href="${static}/js/utils/listRight/listRight.css">
<link type="text/css" rel="stylesheet" href="${static}/plugin/checkBox/dist/checkbox.min.css">
<link type="text/css" rel="stylesheet" href="${static}/page/back/maintainRecord/swiper/swiper.min.css">
<link type="text/css" rel="stylesheet" href="${static}/js/utils/slider/slider.css">
<link type="text/css" rel="stylesheet" href="${static}/plugin/select2-develop/dist/css/select2.min.css">
<link type="text/css" rel="stylesheet" href="${static}/plugin/wdScrollTab/css/TabPanel.css?V4.1-03082101">
<link type="text/css" rel="stylesheet" href="${static}/css/adminlte.min.css">
<link type="text/css" rel="stylesheet" href="${static}/css/common.css">




<script type="text/javascript" src="${static}/js/jquery.min.js"></script>
<script type="text/javascript" src="${static}/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${static}/plugin/layer/layer.js"></script>
<script type="text/javascript" src="${static}/plugin/layui/layui.js"></script>
<script type="text/javascript" src="${static}/plugin/countdown/countdown.js"></script>
<script type="text/javascript" src="${static}/js/i-jquery.js?r=85145"></script>
<script type="text/javascript" src="${static}/js/main.js?v=123"></script>
<script type="text/javascript" src="${static}/js/imgClickBig.js"></script>
<script type="text/javascript" src="${static}/js/jquery.cookie.min.js?v=123456"></script>
<script type="text/javascript" src="${static}/plugin/datatable/media/js/jquery.dataTables.js"></script>
<script type="text/javascript" src="${static}/plugin/datatable/media/js/dataTables.bootstrap.js"></script>
<script type="text/javascript" src="${static}/js/jquery.timeago.js"></script>
<script type="text/javascript" src="${static}/js/jquery.form.js"></script>
<script type="text/javascript" src="${static}/plugin/bootstrap-select/js/bootstrap-select.js"></script>
<script type="text/javascript" src="${static}/plugin/drag/drag.js"></script>
<script type="text/javascript" src="${static}/plugin/calendar/simple-calendar.js"></script>
<script type="text/javascript" src="${static}/plugin/weather/jquery.leoweather.min.js"></script>
<script type="text/javascript" src="${static}/js/material-decomposition.js?r=123sdf"></script>
<script type="text/javascript" src="${static}/js/processHelper.js?r=324242"></script>
<script type="text/javascript" src="${static}/js/checkGroup.js?r=85145"></script>
<script type="text/javascript" src="${static}/js/iDistpicker.js?r=85145"></script>
<script type="text/javascript" src="${static}/plugin/bootstrap-datetimepicker-master/js/bootstrap-datetimepicker.js"></script>
<script type="text/javascript" src="${static}/plugin/bootstrap-datetimepicker-master/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript" src="${static}/js/pmHelper.js"></script>
<script type="text/javascript" src="${static}/js/formUtil.js"></script>
<script type="text/javascript" src="${static}/js/layer-date-format.js"></script>
<script type="text/javascript" src="${static}/js/dateUtil.js"></script>
<script type="text/javascript" src="${static}/js/iUpload.js"></script>
<script type="text/javascript" src="${static}/plugin/eachrt4.1/echarts.js"></script>
<script type="text/javascript" src="${static}/plugin/jquery-plugin-circliful-master/js/jquery.circliful.js"></script>
<script type="text/javascript" src="${static}/plugin/utils/numberUtils.js"></script>
<script type="text/javascript" src="${static}/js/checkWindowClose.js"></script>
<script type="text/javascript" src="${static}/js/utils/common/fileUtils.js"></script>
<script type="text/javascript" src="${static}/js/utils/common/arrayUtils.js"></script>
<script type="text/javascript" src="${static}/js/utils/common/arrayUtils.js"></script>
<script type="text/javascript" src="${static}/js/utils/common/formUtil.js"></script>
<script type="text/javascript" src="${static}/js/utils/common/layer-tip.js"></script>

<script type="text/javascript" src="${static}/plugin/select2-develop/dist/js/select2.js"></script>
<script type="text/javascript" src="${static}/plugin/select2-develop/dist/js/pinyin.js"></script>

<!-- 生成二维码-->
<script type="text/javascript" src="${static}/plugin/qrcode/jquery.qrcode.js"></script>
<script type="text/javascript" src="${static}/plugin/qrcode/qrcode.js"></script>
<script type="text/javascript" src="${static}/plugin/qrcode/utf.js"></script>
<script type="text/javascript" src="${static}/plugin/JsBarcode-master/dist/JsBarcode.all.js"></script>

<!-- 树插件 -->
<link rel="stylesheet" href="${static}/plugin/ztree/zTreeStyle/zTreeStyle.css" />
<script type="text/javascript" src="${static}/plugin/ztree/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="${static}/js/PullDownTreeUtil2.js"></script>
<script src="${static}/plugin/jsPlumb/js/jsplumb.js"></script>
<script src="${static}/plugin/jsPlumb/flowchart-util.js"></script>

<script src="${static}/js/utils/listRight/listRightUtil.js"></script>
<script src="${static}/js/utils/checkUtils/checkUtils.js"></script>
<script src="${static}/page/back/patrolStatic/js/utils.js"></script>
<script src="${static}/js/utils/slider/slider.js"></script>
<script src="${static}/page/back/shuju/js/fullscreen.js"></script>
<script src="${static}/page/back/maintainRecord/swiper/swiper.min.js"></script>

<script  src="${static}/plugin/datatable/JSZip-2.5.0/jszip.min.js"></script>
<script  src="${static}/plugin/datatable/pdfmake-0.1.36/pdfmake.min.js"></script>
<script  src="${static}/plugin/datatable/Buttons-1.5.6/js/dataTables.buttons.js"></script>
<script  src="${static}/plugin/datatable/Buttons-1.5.6/js/buttons.flash.min.js"></script>
<script  src="${static}/plugin/datatable/Buttons-1.5.6/js/buttons.html5.js"></script>
<script  src="${static}/plugin/datatable/Buttons-1.5.6/js/buttons.print.js"></script>
<script  src="${static}/js/utils/table2excel/table2excel.js"></script>
<script  src="${static}/js/common.js"></script>
<!--<script  src="${static}/js/sysIndex.js"></script>-->


<style type="text/css">
    .div-main{
        min-width:1660px;
    }
    .chooseRow {
        background-color: #fefeca !important;
    }

</style>
<div class="page-content-s" style="margin-bottom: 50px;">
    <div class="oper-search">
        <form class="form-inline">

            <div class="form-group">
                <label>所属公司：</label>
                <input type="text" id="entityidtree" readonly="readonly" onclick="entityidTree()" value="" class="form-control search-cache width-180" placeholder="">
                <input type="hidden" id="entityidvalue" value="" name="entityid" class="form-control search-cache">
            </div>

            <div class="form-group">
                <label>名称：</label>
                <input id="name" type="text" class="form-control search-cache width-180" placeholder="请输入名称" autocomplete="off"/>
            </div>
            <div class="form-group">
                <label>编号：</label>
                <input id="sn" type="text" class="form-control search-cache width-180" placeholder="请输入编号" autocomplete="off"/>
            </div>
            <div class="form-group">
                <label>设备名称：</label>
                <input id="devname" type="text" class="form-control search-cache width-180" placeholder="请输入设备名称" autocomplete="off"/>
            </div>
            <div class="form-group">
                <label>设备编号：</label>
                <input id="devsn" type="text" class="form-control search-cache width-180" placeholder="请输入设备编号" autocomplete="off"/>
            </div>
            <div class="form-group">
                <label>责任人：</label>
                <input id="maintainer" type="text" class="form-control search-cache width-180" placeholder="请输入责任人" autocomplete="off"/>
            </div>
            <div class="form-group">
                <label>养护类别：</label>
                <select id="type" class="form-control search-cache width-180">
                    <option value="">未选择</option>

                    <option value="24">日常自主保全</option>

                    <option value="467">test</option>

                    <option value="468">111</option>

                    <option value="25">一级保全</option>

                    <option value="26">二级保全</option>

                    <option value="27">项修计划</option>

                    <option value="105">大修计划</option>

                    <option value="28">其他养护</option>

                </select>
            </div>
            <div class="form-group">
                <span class="btn btn-sm glyphicon glyphicon-search" onclick="searchBtn()">搜索</span>
            </div>
            <div class="form-group">
                <a href="/sys/test" class="btn btn-default btnTool" title="新增用户" data-click-binded="true" onclick="addNew(this);return false;"><i class="fa fa-plus"></i> 新增</a>
                <span class="btn btn-sm glyphicon glyphicon-plus" power="MaintainPlanController.add" powertype="1" onclick="add()">添加</span>
                <span class="btn btn-sm glyphicon glyphicon-import"  onclick="importExcel()">导入</span>
                <span class="btn btn-sm glyphicon glyphicon-export" onclick="exportPlan()">导出</span>
            </div>
        </form>
    </div>
    <div class="data-list" style="padding-left: 0px;">
        <table class="dtable Main_dtable">
            <thead>
            <tr>
                <th style="min-width: 30px;">ID</th>
                <th style="min-width: 100px;">年龄</th>
                <th style="min-width: 100px">性别</th>
                <th style="min-width: 60px">姓名</th>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
    </div>
</div>
<!-- 右边侧滑 -->
<div class="rightdata" style="background-color:#FFFFFF;z-index:19960312;"></div>
<script src="http://demo.windasoft.com:8080/windaedm/js/excelImportHelper.js"></script>
<iframe class="exportIframe" style="border: none; width: 0; height: 0"></iframe>
<!-- 树插件 -->
<script type="text/javascript" src="${static}/plugin/ztree/jquery.ztree.all-3.5.min.js"></script>
<link rel="stylesheet" href="${static}/plugin/ztree/zTreeStyle/zTreeStyle.css" />
<script type="text/javascript" src="${static}/js/PullDownTreeUtil2.js"></script>
<script>

    function addNew(obj) {
        var $this = $(obj);
        var url = $this.data("href") || $this.attr("href");
        var title = $this.data("title") || $this.attr("title");
        js.addTabPage($this,title,url,true,true);

    }

    function exportPlan() {
        sys.confirm("确定要导出所有计划么？", function() {
            //var dpage = table.DataTable().page.info();
            $(".exportIframe").attr("src","maintainPlan/export?" + getSearchPara()+"&exp_ctrl=cur_conditions_page");
        });
    }
    function entityidTree() {
        clearTree("entityid")
        PullDownTree_obj.init("http://demo.windasoft.com:8080/windaedm/manage/findEntity?isEntity=1&withAll=1",
            "#entityidtree", "", "#entityidvalue", false);
    }
    function clearTree(name){
        $("#"+name+"tree").val("");
        $("#"+name+"value").val("");
    }

    var excelImportHelper = new ExcelImportHelper();
    function importExcel(){

        sys.window(null,"导入","http://demo.windasoft.com:8080/windaedm/manage/genericImportPage?importUrl=import/importMainPlanExcel&templateUrl=u/template/养护计划导入模板.xlsx","490px","240px","");

    }

    //console.clear();
    //log("养护计划列表");

    function getSearchPara() {
        var name = $("#name").val().trim();
        var sn = $("#sn").val().trim();
        var devname = $("#devname").val().trim();
        var devsn = $("#devsn").val().trim();
        var maintainer = $("#maintainer").val().trim();
        var type = $("#type").val();
        var param = 'devname='+devname+'&devsn='+devsn
            +'&maintainer='+maintainer + '&name=' + name + '&sn=' + sn + "&type=" + type
            + "&entityid=" + (parseInt($("[name='entityid']").val()) || "");
        return param;
    }

    function getSearchUrl(){
        var url = '/sys/mockDatas?' + getSearchPara();
        url = encodeURI(url);
        return url;
    }

    //注意：选项卡 依赖 element 模块，否则无法进行功能性操作
    var dataTable = $(".Main_dtable");
    $(function() {
        var noticetimeTypeMap = {0:"年",1:"月",2:"天",3:"小时"};
        sys.useSimpleRetrieveData();
        var staticPrefix = "${static}";
        var config = sys.DynamicDatabeConfig(staticPrefix,getSearchUrl(), [ {
            data : "id",
        },
            {
                data : 'age',
            },
            {
                data : 'sex',
                render : function(row, type, data, meta) {
                    console.log(row);
                    return data.sex==0?'女':'男';
                }
            },
            {
                data : 'name',
            },
            /*{
                data : 'devsn'
            },
            {
                data : 'typevalue'
            },
            {
                data : 'nickname'
            },
            {
                data : 'cycle',
                render : function(row, type, data, meta) {
                    return getCycle(data.cycle,data.cycle_unit);
                }
            },
            {
                data : 'notice_time',
                render : function(row, type, data, meta) {
                    if (data.notice_time == null) {
                        return "无";
                    }
                    return data.notice_time + noticetimeTypeMap[data.notice_unit];
                }
            },
            {
                data : 'cycle_num',
                render : function(row, type, data, meta) {
                    if (data.is_add_task != 1) {
                        return "已完成" + data.did_num + "次养护";
                    }
                    return data.did_num+"/"+data.cycle_num;
                }
            },
            {
                data : 'start_time',
                render : function(row, type, data, meta) {
                    return data.start_time && data.start_time.substring(0,10);
                }
            },
            {
                data : 'end_time',
                render : function(row, type, data, meta) {
                    if (data.plan_out_date == 1) {
                        var html = '<span';
                        html += ' style="color:red !important;">';
                        html += data.end_time && data.end_time.substring(0,10);
                        html += '</span>';
                        return html;
                    }
                    return data.end_time && data.end_time.substring(0,10);
                }
            },*/
            /* {
                data : null,
                render : function(data) {
                    return data.is_add_task==1?"是":'<span style="color: #ec971f;">否</span>';
                }
            }, */
            /*{
                data : 'enabled',
                render : function(row, type, data, meta) {
                    return data.enabled==1?"是":'<span style="color: #ec971f;">否</span>';;
                }
            },
            {
                data : null,
                render : function(data) {
                    return getOperHtml(data.id,data.is_add_task,data.rid, data.enabled,data.plan_out_date);
                }
            },*/
        ],true, {ordering:true});
        //禁止排序
        config.bSort=false;
        config.aLengthMenu = [15,25,50,100];
        dataTable.dataTable(config).api().draw();
    })
    // 选择养护计划
    function window1(icon, title, url, width, heigth,type) {
        var t = title;
        if (icon != null) {
            t = '<img src="'+icon+'" width="20"/>' + title;
        }
        layer.open({
            type : 2,
            title : t,
            maxmin : true,
            shadeClose : false, //点击遮罩关闭层
            shade : [ 0.1, '#fff' ],
            area : [ width + "", heigth + "" ],
            content : url
        });
    }

    function del(id) {
        stopPropagation();
        sys.confirm("确定删除该数据吗？", confirmdel);
        function confirmdel() {
            sys.getApiData("maintainPlan/del", {
                id : id
            }, back, "post");
            function back(data) {
                if (data.code == 0) {
                    //data.url="wzff/list";
                }
                sys.msg(data);
                parent.dataTable.api().ajax.reload(null,false);
            }
        }
    }

    function searchBtn(){
        dataTable.api().ajax.url(getSearchUrl()).load(null, false).draw();
    }

    function getCycle(cycle,cycle_unit){
        var unit = cycle_unit==1?"天":cycle_unit==2?"周":"个月";
        return cycle+unit;
    }

    function getOperHtml(id,is_add_task,rid, enabled, plan_out_date){
        console.log(plan_out_date);
        var  html = '';
        html += '<a power="MaintainPlanController.edit" powertype="1" class="btn glyphicon glyphicon-pencil btn-xs" onclick="edit('+id+')">修改</a>&nbsp;';
        html += '<a power="MaintainPlanController.del" class="btn glyphicon glyphicon-trash btn-xs" onclick="del('+id+')">删除</a>';
        if(is_add_task==0 && enabled){
            if (!rid && plan_out_date == 0)
                html += '&nbsp;<a power="MaintainPlanController.addrecord" class="btn btn-xs glyphicon glyphicon-plus" onclick="addRecord('+id+')">添加记录</a>';

        }
        return html;
    }

    // 添加计划
    function add() {
        loadHtml("http://demo.windasoft.com:8080/windaedm/maintainPlan/addMaintainPlan");
    }

    // 编辑计划
    function edit(id) {
        stopPropagation();
        loadHtml("http://demo.windasoft.com:8080/windaedm/maintainPlan/editMaintainPlan?id="+id);
    }

    // 计划详情
    function detail(id){
        stopPropagation();
        //sys.toDetailPage("http://demo.windasoft.com:8080/windaedm/maintainPlan/detailMaintainPlan?planid="+id,"计划详情",'');
        loadHtml("http://demo.windasoft.com:8080/windaedm/maintainPlan/detailMaintainPlan?planid="+id);
    }

    // 添加记录
    function addRecord(id){
        loadHtml("http://demo.windasoft.com:8080/windaedm/maintainPlan/addMaintainRecord?fromMaintainPlan=1&planid="+id);
    }

    function changeSN(data){
        var html = '';
        if(data.is_add_task == 1){
            // TODO 有养护任务,但是没有养护记录，显示待养护图标
            if (!data.rid) {
                html += '<a style = ";cursor: pointer;" onclick="detail('+data.id+')">' + data.sn + '</a>';
                html += '<img width="16px" height="16px" style="margin-left:5px;" src="http://demo.windasoft.com:8080/windaedm/img/daiyanghu2.png" title="待养护">'
            } else {
                html += '<a style = "cursor: pointer;" onclick="detail('+data.id+')">' + data.sn + '</a>';
            }
        }else{
            if(!data.rid){
                html += '<a style = "cursor: pointer;" onclick="detail('+data.id+')">' + data.sn + '</a>';
                html += '<img width="16px" height="16px" style="margin-left:5px;" src="http://demo.windasoft.com:8080/windaedm/img/daiyanghu2.png" title="待养护">'
            }else{
                html += '<a style = "cursor: pointer;" onclick="detail('+data.id+')">' + data.sn + '</a>';
            }
        }
        return html;
    }

    // log to console
    function log(msg) {
        console.log("%c[LOG-DEBUG-INFO]：" + msg, "font-size: 18px; color: red;");
    }

    /* 侧滑 */
    function initRightPage() {
        $(".rightdata").css({
            "position" : "fixed",
            "top" : "100px",
            "right" : "-425px"
        });
        $(".rightdata").height($(window).height()-150);
        $(".rightdata").width(400);

    }
    function closeRightPage() {
        $(".rightdata").animate({right:-425},300);
    }

    function changeLeftData(id) {
        $.post("maintainPlan/getRightPage",{planId:id},function(data){
            $(".rightdata").empty();
            $(".rightdata").append(data);
            $(".rightdata").show().animate({right:0},300);
        })
    }
    //初始化
    initRightPage();

    //点击事件
    $('.dtable tbody').on('click', 'tr', function () {
        $('.dtable tbody tr').not($(this)).removeClass("chooseRow");
        $(this).addClass("chooseRow");
        var data = $('.dtable').DataTable().row(this).data();
        changeLeftData(data.id);
    } );

    function stopPropagation() {
        var e = window.event;
        if(e.stopPropagation) { //W3C阻止冒泡方法
            e.stopPropagation();
        } else {
            e.cancelBubble = true; //IE阻止冒泡方法
        }
    }
    function isDeviceUnAvailable(devid) {
        var flag = false;
        $.ajax({
            url : "http://demo.windasoft.com:8080/windaedm/maintainPlan/isUnAvailableDevice?devid=" + devid,
            type : 'get',
            success : succ,
            error : err,
            anysc : false
        });
        function succ(data) {
            if (data.code == 0) {
                flag = true;
            }
        }
        function err() {
            layer.msg("请求异常");
        }
        return flag;
    }

    function getShowNameHtml(data) {
        var html = data.devname;
        if (+data.device_has_removed == 1) {
            html = '';
            html += "<s style='color:red;cursor:help;' title='设备不可用(已删除)'>" + data.devname + "</s>"
            return html;
        }
        if (+data.is_scrap == 1) {
            html = '';
            html += "<s style='color:red;cursor:help;' title='设备不可用(已报废)'>" + data.devname + "</s>"
            return html;
        }
        if (+data.is_sold == 1) {
            html = '';
            html += "<s style='color:red;cursor:help;' title='设备不可用(已变卖)'>" + data.devname + "</s>"
            return html;
        }
        return html;
    }
</script>
